// tslint:disable
import { Component, OnInit, Input } from '@angular/core';
import { AppGlobalService } from 'src/app/shared/service/app-global.service';
import { PageModalService } from 'src/app/shared/service/page-modal-service';
@Component({
  selector: 'app-lai-jian-achievement',
  templateUrl: './lai-jian-achievement.component.html',
  styleUrls: ['./lai-jian-achievement.component.scss'],
})
export class LaiJianAchievementComponent implements OnInit {
  @Input() tagData: any;
  defaultImg = 'assets/img/default_img.png';
  achieveData = [];
  achieveMentBoxId = 'achieve_box_id';
  achieveMentMiddleLeftBoxSpanId = 'middle_left_box_span_id';
  achieveMentLeftLabel = '';
  achieveMentRightLabel = '';
  achieveMentLeftValue = 0;
  achieveMentRightValue = 0;
  achieveMentLeftList: any;
  achieveMentRightList: any;
  defaultTab = true;
  unitLabel = '元';
  bottomLeftList: any;
  bottomRightList: any;

  // 1.7.0 新增按钮
  rightButton: any;
  //   {
  //     "type":"tag",
  //     "style":"tag.achievement",
  //     "name":"XXX",
  //     "linearLayout":"body",
  //     "boxWidth":null,
  //     "listData":[
  //         {
  //             "data":"1080",
  //             "label":"今日业绩",
  //             "style":"",
  //             "text":1080,
  //             "list":[
  // {
  //             "data":"0",
  //             "style":"",
  //             "label":"发转店"
  //         },
  //         {
  //             "data":"1",
  //             "label":"发出租",
  //             "text":1,
  //             "style":""
  //         },
  //         {
  //             "data":"0",
  //             "style":"",
  //             "label":"发找店"
  //         },
  //         {
  //             "data":"0",
  //             "style":"",
  //             "label":"电话量"
  //         },
  //         {
  //             "data":"0",
  //             "style":"",
  //             "label":"推荐量"
  //         }]
  //         },{
  //             "data":"1080",
  //             "label":"本月业绩",
  //             "style":"",
  //             "text":1080,
  //             "list":[
  // {
  //             "data":"0",
  //             "style":"",
  //             "label":"发转店"
  //         },
  //         {
  //             "data":"1",
  //             "label":"发出租",
  //             "text":1,
  //             "style":""
  //         },
  //         {
  //             "data":"0",
  //             "style":"",
  //             "label":"发找店"
  //         },
  //         {
  //             "data":"0",
  //             "style":"",
  //             "label":"电话量"
  //         },
  //         {
  //             "data":"0",
  //             "style":"",
  //             "label":"推荐量"
  //         }]
  //         }

  //     ]
  // }

  constructor(
    private appGlobalService: AppGlobalService,
    private pageModalService: PageModalService
  ) { }

  ngOnInit() {
    this.achieveMentBoxId += new Date().getTime();
    this.achieveMentMiddleLeftBoxSpanId += new Date().getTime();
    const len = this.tagData.data.length;
    // 新标签
    if (this.tagData.name !== 'appMyStatisticWorkTag') {
      if (this.tagData.bottom && this.tagData.bottom.link && this.tagData.bottom.link[0]) {
        this.rightButton = this.tagData.bottom.link[0];
        this.rightButton['link'] = this.tagData.bottom.link[0];
      }



    } else {
      if (len > 1) {
        for (let i = 0; i < len; i++) {
          const v = this.tagData.data[i];
          if (i === 0 && v.label) {
            this.achieveMentLeftLabel = v.label;
            this.achieveMentLeftValue = v.data;
            this.achieveMentLeftList = v.list;
            if (this.achieveMentLeftList !== undefined) {
              const len = this.achieveMentLeftList.length;
              this.bottomLeftList = this.achieveMentLeftList.slice(2, len);
              // 如果只配置了一条记录
              if (this.bottomLeftList && this.bottomLeftList.length === 1) {
                this.achieveMentLeftList.cssType = 1;
                this.achieveMentLeftList[0] = this.bottomLeftList[0]
                this.bottomLeftList = [];
              } else {
                this.achieveMentLeftList.cssType = 0;
              }
            }
          } else if (i === 1 && v.label) {
            this.achieveMentRightLabel = v.label;
            this.achieveMentRightValue = v.data;
            this.achieveMentRightList = v.list;
            if (this.achieveMentLeftList !== undefined) {
              const len = this.achieveMentRightList.length;
              this.bottomRightList = this.achieveMentRightList.slice(2, len);
              if (this.bottomRightList && this.bottomRightList.length === 1) {
                this.achieveMentRightList.cssType = 1;
                this.achieveMentRightList[0] = this.bottomRightList[0]
                this.bottomRightList = [];
              } else {
                this.achieveMentRightList.cssType = 0;
              }
            }

          }
          // this.achieveData.push(v);
        }
      } else if (len === 1) {
        // console.log('msg len ====1 ');
      }
    }

  }

  getTodayData() {
    this.defaultTab = true;
    document.getElementById(this.achieveMentBoxId).style.backgroundImage = 'url("../../../assets/icon/home_yjbg-01@3x.png")';
  }
  getMonthData() {
    this.defaultTab = false;
    document.getElementById(this.achieveMentBoxId).style.backgroundImage = 'url("../../../assets/icon/home_yjbg-02@3x.png")';
  }

  getNgStyle(str) {
    try {
      return JSON.parse(str);
    } catch (error) {
      return {};
    }
  }

  go(obj) {
    this.pageModalService.openPage(obj);
  }
}

